<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
         <%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" +request.getServerPort() + path + "/";
%> 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<title>Insert title here</title>
 <link rel="stylesheet" type="text/css" href="../Styles/admin-all.css" />
  <link rel="stylesheet" type="text/css" href="../layui/css/layui.css" />

    <link rel="stylesheet" type="text/css" href="../Styles/base.css" />
    <link rel="stylesheet" type="text/css" href="../Styles/bootstrap.min.css" />
    <script type="text/javascript" src="../Scripts/jquery.min.js"></script>
    <script type="text/javascript" src="../Scripts/bootstrap.min.js"></script>
    <script type="text/javascript" src="../Scripts/index.js"></script>
    <script type="text/javascript" src="<%=basePath %>/js/vue.min.js"></script>
    <script type="text/javascript" src="../layui/layui.js"></script>
    <script src="<%=basePath %>/laypage/laypage.js"></script>
    <style type="text/css">
    #div1{
margin: 20px;

}
img{
width: 100%;
margin-bottom: 10px;
}
#but{
width: 100%;
height: 50px;
}
#button{
float: right;
margin-right: 20px;
margin-bottom: 8px;
}
#button1{
text-align: center;
}
#laypage{
border-right-color: white;
padding-left: 150px;
}
#tr3{
text-align: center;
}
    </style>
</head>
<body>
<div id="bigdiv">
<div id="div1"><a href="../index.jsp">交流论坛</a> 》发布帖子</div>
<!-- Unnamed (水平线) -->
      <img id="u6_line" class="img " src="../img/u199_line.png"/>
      </div>
      <div id="but">
      <h4>论坛版块管理</h4>
       <button type="button" class="btn btn-primary"  data-toggle="button" id="button" class="but" onclick="getBacks()">返回</button>
      </div>
      <div id="tables">
      <form action="../queryRroed" >
      <table class="table table-bordered" >
    
		<thead >
			<tr>
				<th colspan=2 >版块名称</th>
				<th>版主</th>
				<th>类型</th>
				<th>发布人</th>
				<th>操作</th>
			</tr>
		</thead>
		
		<tbody id="iddf">
			<tr v-for="list in data">	
			
		<td colspan=2 ><input type="text" name="ptmain" value="{{list.bor_name }}" id="ptmain2" class="form-control"  placeholder="请输入您要发表的主题" style="width: 450px;">
		</td>
				<td><input type="text" name="ptmain" value="{{list.bor_owner }}" id="ptmain" class="form-control" placeholder="请输入您要发表的主题" style="width: 250px;">
				 <input type="hidden" name="borid" id="borid" value="{{list.bor_id}}"> 
				</td>
				<td><select name="ptboards" class="form-control" id="ptboards"  style="width: 150px;"  >
						<option value="1" v-if="list.bor_style==1" v-bind:selected>发帖直接显示</option>
						<option  value="0" v-if="list.bor_style==0" v-bind:selected>发帖需要审批</option>
					</select></td>
				<td>{{list.bor_nameid}}</td>
				<th><button type="button" class="btn btn-success" v-on:click="deleteBord(list.bor_id)">删除</button>	</th></tr>
		
			<tr><td id="laypage" > </td><td colspan="5"> <select name="ptboard1" class="form-control" id="pages" style="width: 150px;" v-on:change="getBoredSet()" >
						<option value="3" selected="selected">按条数分页</option>
						<option value="5">按5条分页</option>
						<option  value="10" >按10条分页</option>
						<option  value="15" >按15条分页</option>
						<option  value="20" >按20条分页</option>
					</select></td></tr>
			</tbody>

			<tr>
				<td colspan=6 ><span>新增版块<i class="layui-icon" style="font-size: 30px; color: #1E9FFF;" onclick="getAddShow()" >  &#xe608;</i>  </span> 
</td>	
			</tr> 
				<tr class="tr1" id="button1">
				<td colspan=6 > <button type="button" class="btn btn-primary"  data-toggle="button" id="but1" class="but" v-on:click="addBored()">保存</button></td>			
			</tr>  
	</table>
	</form>
      </div>
</body>
<script type="text/javascript">
var vnm=new Vue({
	el:"#tables",
	data:{
		data:[],
		curr:'1',
	
	},
	methods:{
	//删除
		   deleteBord:function(bor_id){
			var dom=this;
			$.ajax({
				url:'../deleteBord',
				type:'post',
				data:{bor_id:bor_id},
				dataType:'json',
				success:function(res){
					alert("删除成功")
					dom.getBoredSet();
				}
			})
		},	//显示
		getBoredSet:function(){
			var dom=this
			var currentPage=this.curr;
			var pagecount=$("#pages").val();
			$.ajax({
				url:'../showBoredPost',
				type:'post',
				data:{currentPage:currentPage,pagecount:pagecount},
				dataType:'json',
				success:function(res){
					  console.log(res.boredPost)  
					dom.data=res.boredPost	
			
					  laypage({
						    cont: $("#laypage"),
						    pages:res.count,  //假设我们获取到的是18（后端计算完总页数后将总页数值传过来，放在这里即可（类似{$totalpage}））.
						    groups:5, //显示几页码 
						    skip: true, //是否开启跳页
						    skin: '#AF0000',
						    curr:currentPage,  //假设我们获取到的是18（后端计算完总页数后将总页数值传过来，放在这里即可（类似{$totalpage}））.
						    groups:pagecount, //显示几页码currentPage,		
						    jump: function(obj, first){ //触发分页后的回调
						        if(!first){ 	//一定要加此判断，否则初始时会无限刷新      
						        	dom.curr=(obj.curr);
						        	dom.getBoredSet();
						        }
						    }
						});    
				}
			})
			
		},
		//分页
	/* 	getPages:function(){
			var pagecount=$("#pages").val();
			alert(pagecount)
			
		}, */
		
		//新增
		/* addBored:function(){
		
			var bor_name=$("#bor_name").val();
			var bor_style=$("#bor_style").val();
			
			var dom=this;
			$.ajax({
				url:'../addBored',
				type:'post',
				data:{bor_name:bor_name,bor_style:bor_style},
				dataType:'json',
				success:function(res){
					alert("添加成功")
					dom.getBoredSet();
				}
			})
		}
	}, */ 
	
		addBored:function(){
		
			obj1=document.getElementsByName("bor_name");
			check_val=[];
			var str="";
			for(i in obj1){
					str+=obj1[i].value+","
					 check_val.push(obj1[i].value);  
					}
			console.log(obj1) 
			obj2=document.getElementsByName("bor_style");
			check_val2=[];
			var str2="";
			for(i in obj2){
					str2+=obj2[i].value+","
			} console.log(str2)   

			var dom=this;
			$.ajax({
				url:'../addBored',
				type:'post',
			 	data:{str:str,str2:str2}, 
				dataType:'json',
				success:function(res){
					alert("添加成功")
					dom.getBoredSet();
				}
			})
		}
	},
	created:function(){
		this.getBoredSet();
	
	}
})	
 function getAddShow() {
	$("#iddf").append(
"<tr id='iddd'><td colspan=2 style='border-right-color: white;'><div class='layui-form-item'><label class='layui-form-label'>版块名称</label> <div class='layui-input-block'><input type='text' name='bor_name' id='bor_name' required  lay-verify='required' placeholder='请输入版块名称' autocomplete='off' class='layui-input' style='width: 90%;'></div> </div></td><td  style='border-right-color: white;'>	<select name='bor_style' class='form-control' style='width: 250px;' id='bor_style' ><option value='1'>发帖直接显示</option><option  value='0' >发帖需要审批</option></select></td><td colspan=3><button type='button' class='btn btn-danger' onclick='getdelete(this)'>清除</button>"+"</td></tr>");
 }
function  getBacks(){
		window.location.href="<%=basePath %>/index.jsp"
	}
	//新增版块
	function getdelete(obj){
				var tr=obj.parentNode.parentNode;
				var tbody=tr.parentNode;
				tbody.removeChild(tr);
	}
	
	 $(document).ready(function(){
		 getquery();
})  
	function getquery() {
		$.ajax({
			url:'../queryRroed',
			type:'post',
			dataType:'json',
			success:function(res){
		
			$.each(res.Bored,function(inx,ele){
						var a=ele.bor_style
						var id=ele.bor_id;
						var borid=$("#borid").val();	
					
						borid=document.getElementsByName("borid");
						for(i in borid){
							console.log(borid[i].value)
						}
					/* 	alert(borid) */
						 $("#borid").each(function(){	
							 var b=$(this).val();
							 console.log(b+"bbb");					
	}); 
						
						
			 $("#ptboards option").each(function(){	
			 /* if(borid[j].value==id){  } */
	 if (parseInt(a) == parseInt($(this).val())) {
		 $(this).attr("selected","selected")
	}		
	}); 
			 }) 
			}
		})
	} 

		/* borid=document.getElementsByName("borid");
		for(j in borid){	
			console.log("数据库"+borid[j].value+"dd")
		} */
		
		  var ptboard=$("#borid").val();
		
		/* for(i in ptboard){
			console.log("kk"+ptboard[i].value)
		} */
	/* 	roleId=document.getElementsByName("bor")
		var borid=$("#bor").val();
		alert(borid)
 	for(j in roleId){
 		console.log("kk"+roleId[j].value)
		for(i in a)
		if(roleId[j].value==a[i]){
		$(roleId[j]).attr('checked',true);

		} 
} */
	/* }) */ 
	
	
</script>
</html>